package com.jjyu.service.impl;


import com.jjyu.entity.Coupon;
import com.jjyu.dao.CouponMapper;
import com.jjyu.service.CouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements CouponService {

    @Autowired
    private CouponMapper couponMapper;

    @Override
    public List<Coupon> getAllCoupons() {
        // 调用Mapper的方法来获取所有的优惠券
        return couponMapper.selectAll();
    }

    @Override
    @Transactional
    public boolean addCoupon(Coupon coupon) {
        // 调用MyBatis Plus的save方法添加优惠券
        return save(coupon);
    }

    @Override
    @Transactional
    public boolean updateCoupon(Coupon coupon) {
        // 调用MyBatis Plus的updateById方法更新优惠券
        return updateById(coupon);
    }

    @Override
    @Transactional
    public boolean removeCoupon(int couponId) {
        // 调用MyBatis Plus的removeById方法删除优惠券
        return removeById(couponId);
    }
}